package com.example.demo.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.UUID;

/**
 * @author gyc
 * @date 2018/1/13
 */
@RestController
@RequestMapping("/session")
public class SessionController {
    private final static Logger logger= LoggerFactory.getLogger(SessionController.class);

    @RequestMapping("/uid")
    public String uid(HttpSession session){
        UUID uid= (UUID) session.getAttribute("uid");
        if(uid==null){
            uid=UUID.randomUUID();
        }
        session.setAttribute("uid",uid);
        session.getCreationTime();
        return session.getId();
    }
}
